import 'package:city_pickers/city_pickers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'package:get/get.dart';
import 'package:xiaomi_shop/app/services/screenAdapter.dart';

import '../controllers/address_add_controller.dart';

class AddressAddView extends GetView<AddressAddController> {
  const AddressAddView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title:
            controller.type == 1 ? const Text('修改收货地址') : const Text('新建收货地址'),
        centerTitle: true,
      ),
      backgroundColor: Colors.grey.shade100,
      body: ListView(
        children: [
          // 姓名/电话
          Container(
            color: Colors.white,
            padding: EdgeInsets.only(
                left: ScreenAdapter.width(30), right: ScreenAdapter.width(30)),
            child: Column(
              children: [
                SizedBox(
                  height: ScreenAdapter.height(150),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        "姓名",
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                      ),
                      SizedBox(
                        width: ScreenAdapter.width(40),
                      ),
                      Expanded(
                          child: TextField(
                        controller: controller.nameEditController,
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                        decoration: InputDecoration(
                          hintText: "请输入收货人姓名",
                          hintStyle:
                              TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                          border: InputBorder.none,
                          contentPadding: EdgeInsets.symmetric(horizontal: 8.w),
                        ),
                      )),
                    ],
                  ),
                ),
                SizedBox(
                  height: ScreenAdapter.height(150),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        "电话",
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                      ),
                      SizedBox(
                        width: ScreenAdapter.width(40),
                      ),
                      Expanded(
                          child: TextField(
                        controller: controller.phoneEditController,
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                        maxLength: 11,
                        keyboardType: TextInputType.number,
                        decoration: InputDecoration(
                          hintText: "请输入收货人电话",
                          hintStyle:
                              TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                          counterText: "",
                          border: InputBorder.none,
                          contentPadding: EdgeInsets.symmetric(horizontal: 8.w),
                        ),
                      )),
                    ],
                  ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: ScreenAdapter.height(20),
          ),
          // 地区/详细地址
          Container(
            color: Colors.white,
            padding: EdgeInsets.only(
                left: ScreenAdapter.width(30), right: ScreenAdapter.width(30)),
            child: Column(
              children: [
                SizedBox(
                  height: ScreenAdapter.height(150),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        "所在地区",
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                      ),
                      SizedBox(
                        width: ScreenAdapter.width(40),
                      ),
                      Expanded(
                          child: TextField(
                        controller: controller.areaEditController,
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                        readOnly: true,
                        decoration: InputDecoration(
                          hintText: "选择地区信息",
                          hintStyle:
                              TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                          border: InputBorder.none,
                          contentPadding: EdgeInsets.symmetric(horizontal: 8.w),
                        ),
                        onTap: () async {
                          print("选择地区信息");
                          Result? result = await CityPickers.showCityPicker(
                              context: context,
                              locationCode: controller.locationCode);
                          print("result $result");
                          controller.areaEditController.text =
                              "${result!.provinceName} ${result.cityName} ${result.areaName}";
                          controller.locationCode = result.areaId!;
                        },
                      )),
                    ],
                  ),
                ),
                Container(
                  height: ScreenAdapter.height(150),
                  alignment: Alignment.center,
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        "详细地址",
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(40)),
                      ),
                      SizedBox(
                        width: ScreenAdapter.width(40),
                      ),
                      Expanded(
                          child: TextField(
                        controller: controller.detailAreaEditController,
                        textAlignVertical: TextAlignVertical.top,
                        style: TextStyle(fontSize: ScreenAdapter.fontSize(44)),
                        decoration: InputDecoration(
                          hintText: "小区、楼牌号等",
                          hintStyle:
                              TextStyle(fontSize: ScreenAdapter.fontSize(44)),
                          border: InputBorder.none,
                          // contentPadding: EdgeInsets.only(bottom: 4),
                        ),
                      )),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
      bottomNavigationBar: Container(
        height: ScreenUtil().bottomBarHeight + ScreenAdapter.height(180),
        child: Stack(
          children: [
            Positioned(
                left: 0,
                right: 0,
                top: 0,
                height: ScreenAdapter.height(180),
                child: Container(
                  margin: EdgeInsets.all(ScreenAdapter.width(30)),
                  color: Colors.orange.shade900,
                  child: TextButton(
                      onPressed: () {
                        controller.addAddress();
                      },
                      child: Text(
                        "保存",
                        style: TextStyle(
                            color: Colors.white,
                            fontSize: ScreenAdapter.fontSize(44),
                            fontWeight: FontWeight.w800),
                      )),
                ))
          ],
        ),
      ),
    );
  }
}
